home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Interactive Reference Guide / C-C++ Interactive Reference Guide.iso / c_ref / csource1 / cenvid / pathadd.bat < prev    next >
DOS Batch File  |  1993-11-15  |  1KB  |  46 lines

  1. @echo off
  2. REM PathAdd.bat - add a directory to the current path, if it's not already there
  3.  
  4. if "%1"=="" GOTO SHOW_HOW
  5. if not "%2"=="" GOTO SHOW_HOW
  6. cenvi %0.BAT %1
  7. GOTO FINI
  8.  
  9. :SHOW_HOW
  10. ECHO PathAdd.bat - Add a directory to the PATH if it's not already there
  11. ECHO USAGE: PathBat DirSpec
  12. GOTO FINI
  13.  
  14.  
  15. GOTO CENVI_EXIT
  16.  
  17. main(argc,argv)
  18. {
  19.    NewDir = argv[1]
  20.    if ( AlreadyInPath(NewDir) ) {
  21.       printf("The Directory \"%s\" is already in PATH.\n",NewDir)
  22.    } else {
  23.       // File is not already in the path, and so append to the end of PATH.
  24.       // If there isn't a semi-colon at the end of PATH already, then add one.
  25.       if ( PATH[strlen(PATH)-1] != ';' )
  26.          strcat(PATH,";")
  27.       // Append this new directory to the end of the path statement
  28.       strcat(PATH,NewDir)
  29.    }
  30. }
  31.  
  32. AlreadyInPath(Dir) // search through path for this Dir, return True if found, else False
  33. {
  34.    len = strlen(Dir)
  35.    p = PATH
  36.    do {
  37.       if ( 0 == strnicmp(p,Dir,len)  && (p[len]==0 || p[len]==';') )
  38.          return(True)
  39.       p = strchr(p,';')
  40.    } while( p++ != NULL )
  41.    return(False)
  42. }
  43.  
  44. :CENVI_EXIT
  45. :FINI
  46.